#define TASK_COUNT_MAX 16
#define ARRAYSIZE(a)		(sizeof(a) / sizeof(a[0]))

struct task_t
{
	int (*call_back)(void);
	int call_ms;//多少ms调用一次
	int success;//成功次数
	int fail;//失败次数
};

struct task_t g_task_array[TASK_COUNT_MAX] = {/*...*/};

void timer_1ms(void)
{
	int i,ret;
	static cnt = 0;
	int (*fun)(void);
	
	for(i = 0;i < TASK_COUNT_MAX;i++)
		if(cnt%g_task_array[i].call_ms == 0)
		{
			fun = g_task_array[i].call_back;
			ret = fun();
			if(ret)	g_task_array[i].success++;
			else		g_task_array[i].fail++;
		}
}

void add_task(struct task_t task)
{
	if(g_task_array[TASK_COUNT_MAX-1] != 0)
	{
		printf("任务队列已满，无法添加\n");
		return;
	}
	g_task_array[ARRAYSIZE(g_task_array)] = task;
}

void remove_task(struct task_t task)
{
	int i;
	for(i = 0;i < TASK_COUNT_MAX;i++)
		if(g_task_array[i] == task)
			g_task_array[i] = 0;
}

